from django.db import models

# Create your models here.


# class CpuTimes(models.Model):
# 	'''cpu消耗指标'''
# 	id = models.AutoField(primary_key=True)
# 	minions_id = models.CharField(max_length=16,verbose_name="minions主机id",db_index=True)
# 	user = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="user")   #支持float类型，decimal_places表示小数位
# 	nice = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="nice")
# 	system = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="system")
# 	idle = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="idle")
# 	iowait = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="iowait")
# 	softirq = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="softirq")
# 	steal = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="steal")
# 	irq = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="irq")
# 	guest = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="guest")
# 	guest_nice = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="guest_nice")
# 	cpupercent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="CPU使用率")
# 	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True,db_index=True)
# 	def __str__(self):
# 		return self.minions_id
# 	class Meta:
# 		db_table = 'OPS_minions_cputimes'
# 		verbose_name_plural = 'CPU监控指标'

class CpuLoad(models.Model):
	'''cpu 负载'''
	id = models.AutoField(primary_key=True)
	minions_id = models.CharField(max_length=16, verbose_name="minions主机id", db_index=True)
	nowpercent = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="当前负载")
	loadone  = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1分钟负载")
	loadfive = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="5分钟负载")
	loadfiften = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="15分钟负载")
	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True, db_index=True)

	def __str__(self):
		return self.minions_id

	class Meta:
		db_table = 'OPS_minions_cpuload'
		verbose_name_plural = 'CPU负载监控指标'

class SysParameters(models.Model):
	'''系统不常变动的值'''
	id = models.AutoField(primary_key=True)
	minions_id = models.CharField(max_length=16, verbose_name="minions主机id", db_index=True)
	usercount = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="登录用户数")
	cpuphysicalcount = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="CPU物理数")
	cpulogiccount = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="CPU逻辑数")
	pids = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="进程数")
	nowtime = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="系统运行小时数")
	cpucurrent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="CPU当前频率")
	memtotal = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="物理内存")
	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True, db_index=True)

	def __str__(self):
		return self.minions_id

	class Meta:
		db_table = 'OPS_minions_sysparameters'
		verbose_name_plural = '系统值监控指标'

class MemeryMinions(models.Model):
	'''内存指标'''
	id = models.AutoField(primary_key=True)
	minions_id = models.CharField(max_length=16, verbose_name="minions主机id", db_index=True)
	total = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="物理内存总数")
	available = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="剩余内存")
	percent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="已用百分比")
	used = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="使用的内存")
	free = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="未使用的内存")
	active = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="在使用内存")
	inactive = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="未使用内存")
	buffers = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="缓存文件系统元数据")
	cached = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="缓存各种东西")
	shared = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="被多个进程使用的内存")
	swap_total = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="总交换内存")
	swap_used = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="已使用的交换内存")
	swap_free = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="可使用的交换内存")
	swap_percent = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="已使用交换内存百分比")
	swap_sin = models.DecimalField(max_digits=16,decimal_places=2, verbose_name="从磁盘交换的内存")
	swap_sout = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="从磁盘换出的内存")
	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True, db_index=True)

	def __str__(self):
		return self.minions_id

	class Meta:
		db_table = 'OPS_minions_memeryminions'
		verbose_name_plural = '内存监控指标'

class DiskIO(models.Model):
	'''磁盘指标'''
	id = models.AutoField(primary_key=True)
	minions_id = models.CharField(max_length=16, verbose_name="minions主机id", db_index=True)
	read_count = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒读取次数")
	write_count = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒写入次数")
	read_bytes = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒读取字节数")
	write_bytes = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒写入字节数")
	read_time = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒内从磁盘读取时间")
	write_time = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒内从磁盘写入时间")
	all_read_count = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="总读取次数")
	all_write_count = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="总写入次数")
	all_read_bytes = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="总读取字节数")
	all_write_bytes = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="总写入字节数")
	all_read_time = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="总内从磁盘读取时间")
	all_write_time = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="总内从磁盘写入时间")
	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True, db_index=True)

	def __str__(self):
		return self.minions_id

	class Meta:
		db_table = 'OPS_minions_diskio'
		verbose_name_plural = '磁盘监控指标'

class NetworkIO(models.Model):
	'''网络指标'''
	id = models.AutoField(primary_key=True)
	minions_id = models.CharField(max_length=16, verbose_name="minions主机id", db_index=True)
	bytes_sent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒发送的字节数")
	bytes_recv = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒收到的字节数")
	packets_sent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒发送的数据包数量数")
	packets_recv = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒接收的数据包数量")
	errin = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒接收时错误的总数")
	errout = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒发送时错误的总数")
	dropin = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒丢弃的数据包总数")
	dropout = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒丢弃的发送的包总数")
	all_bytes_sent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="发送的字节数")
	all_bytes_recv = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="收到的字节数")
	all_packets_sent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="发送的数据包数量")
	all_packets_recv = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="接收的数据包数量")
	all_errin = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="接收时错误的总数")
	all_errout = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="发送时错误的总数")
	all_dropin = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="丢弃的数据包总数")
	all_dropout = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="丢弃的发送的包总数")
	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True, db_index=True)

	def __str__(self):
		return self.minions_id

	class Meta:
		db_table = 'OPS_minions_networkio'
		verbose_name_plural = '网络监控指标'

class NetStat(models.Model):
	'''TCP连接指标'''
	id = models.AutoField(primary_key=True)
	minions_id = models.CharField(max_length=16, verbose_name="minions主机id", db_index=True)
	established= models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒读取次数")
	last_ack = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒写入次数")
	time_wait = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒读取字节数")
	syn_sent = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒写入字节数")
	close_wait = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒内从磁盘读取时间")
	listen = models.DecimalField(max_digits=16,decimal_places=2,verbose_name="1秒内从磁盘写入时间")
	create_time = models.DateTimeField(verbose_name='收录时间', auto_now_add=True, db_index=True)

	def __str__(self):
		return self.minions_id

	class Meta:
		db_table = 'OPS_minions_netstat'
		verbose_name_plural = 'TCP端口连接监控指标'
